layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form;
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    form.on("submit(addAlbum)",function(data){
        //弹出loading
        var index = layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        var file = $('#showImg').get(0).files[0];
        var formData = new FormData();
        formData.append("file", file);
        formData.append("name",$('#name').val());
        formData.append("showFlag",$('#showFlag').val());
        formData.append("introduction",$('#introduction').val());
        formData.append("location",$('#location').val());
        $.ajax({
            type: "post",
            url:"/manage/album/addData",
            dataType: "json",
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
                if(result.flag == "success"){
                    layer.close(index);
                    top.layer.msg("创建成功！", {icon: 1});
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();

                }else{
                    layer.msg("创建失败", {icon: 2});
                }
            }, error: function () {
                layer.msg("创建失败", {icon: 2});
            }

        });
    });

    form.on("submit(updateAlbum)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            type: "post",
            url:"/manage/album/updateData",
            dataType: "json",
            data: $("#submitForm").serialize(),
            success: function (result) {
                if(result.flag == "success"){
                    top.layer.close(index);
                    top.layer.msg("更新成功！", {icon: 1});
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }else{
                    layer.msg("更新失败", {icon: 2});
                }
            }
        });
    });

    //关闭
    $(".close").on("click",function(){
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    });

});